﻿
using UnityEngine;
using UnityEngine.UI;

namespace XFGameFramework.TweenSystem
{
    /// <summary>
    /// Slider动画拓展
    /// </summary>
    public static class SliderExtensions
    {

        /// <summary>
        /// 渐变value
        /// </summary>
        /// <param name="slider">Slider对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>

        public static TweenerCore<float> TweenValue(this Slider slider, float target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        {
            return TweenManager.ComponentTween(slider, slider.value, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenValue, delay,0,loopCount);
        }

        /// <summary>
        /// 渐变NormalizedValue
        /// </summary>
        /// <param name="slider">Slider对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<float> TweenNormalizedValue(this Slider slider, float target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0, int loopCount = -1)
        { 
            return TweenManager.ComponentTween(slider, slider.normalizedValue, target, duration, loop, ease, curve, ingoreTimeScale, OnTweenNormalizedValue, delay,0,loopCount);
        }


        internal static void OnTweenValue(TweenerCore<float> tweener)
        {
            if (tweener.Component is Slider)
            {
                Slider slider = tweener.Component as Slider;
                slider.value = tweener.Value;
            }
        }

        internal static void OnTweenNormalizedValue(TweenerCore<float> tweener)
        {
            if (tweener.Component is Slider)
            {
                Slider slider = tweener.Component as Slider;
                slider.normalizedValue = tweener.Value;
            }
        }


    }

}

